import 'package:flutter/material.dart';
import 'package:flutter_09_game/config/app_color.dart';
import 'package:flutter_09_game/config/app_routes.dart';
import 'package:flutter_09_game/generated/locales.g.dart';
import 'package:flutter_09_game/widgets/button/common_button.dart';
import 'package:flutter_09_game/widgets/dialog/common_normal_sheet.dart';
import 'package:flutter_09_game/widgets/input/common_text_field.dart';
import 'package:flutter_09_game/widgets/widget_profile_item.dart';
import 'package:flutter_09_game/widgets/widget_verification_box.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'safety_verify_logic.dart';

class SafetyVerifyPage extends StatelessWidget {
  const SafetyVerifyPage({super.key, this.isDelete});

  final bool? isDelete;


  Future show({
    String? title,
  }) async {
    return await CommonNormalSheet(
      title: title,
      child: this,
    ).show();
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SafetyVerifyLogic>(
        init: SafetyVerifyLogic(),
        builder: (logic) {
          return Container(
            constraints: BoxConstraints(
              maxHeight: 500.h,
            ),
            padding: EdgeInsets.symmetric(horizontal: 16.w),
            child: SingleChildScrollView(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  WidgetProfileItem(LocaleKeys.fundPassword.tr,
                      WidgetVerificationBox(
                    onValueChanged: (text) {
                      logic.fundPassword.value = text;
                      logic.validateForm();
                    },
                  ),
                      rightWidget: GestureDetector(
                        onTap: () {


                          // Get.until((routting) => routting.settings.name == AppRoutes.profileSafetyCenterPage);

                          Get.toNamed(AppRoutes.profileFindFundPasswordPage);
                          //     ?.then((value) {
                          //   if (value == true) {
                          //     Get.back();
                          //   }
                          // });
                        },
                        child: Text(
                          LocaleKeys.forgotFundPassword.tr,
                          style: TextStyle(
                            color: AppColor.primary.withOpacity(0.7),
                            fontSize: 12.sp,
                          ),
                        ),
                      )),

                  16.verticalSpaceFromWidth,
                  // securityQuestion
                  Obx(() {
                    return WidgetProfileItem(
                        LocaleKeys.securitySafeQuestion.tr,
                        Container(
                          padding: EdgeInsets.symmetric(
                              vertical: 14.w, horizontal: 12.w),
                          decoration: BoxDecoration(
                              color: AppColor.color2D2F35,
                              borderRadius: BorderRadius.circular(8.w)),
                          child: Row(
                            children: [
                              Text(
                                logic.securityQuestion.value.question
                                        ?.Content ??
                                    '',
                                style: TextStyle(
                                    color:
                                        AppColor.textPrimary.withOpacity(0.3),
                                    fontSize: 14.sp,
                                    fontWeight: FontWeight.w500),
                              )
                            ],
                          ),
                        ));
                  }),
                  16.verticalSpaceFromWidth,

                  Obx(() {
                    return WidgetProfileItem(
                        (logic.securityQuestion.value.notice ?? '').isNotEmpty
                            ? '${LocaleKeys.securityAnswerHint.tr}:'
                            : LocaleKeys.enterSecurityAnswer.tr,
                        leftStr: logic.securityQuestion.value.notice,
                        CommonTextField(
                          textEditingController: logic.answerController,
                          hintText: LocaleKeys.enterSecurityAnswer.tr,
                          backgroundColor: Colors.black.withOpacity(0.3),
                          borderColor: AppColor.textPrimary.withOpacity(0.15),
                          maxLength: 100,
                          onChanged: (tex) {
                            logic.validateForm();
                          },
                        ));
                  }),
                  24.verticalSpaceFromWidth,
                  Obx(() => CommonButton.expend(
                        title: LocaleKeys.confirm.tr,
                        enable: logic.isFormValid.value,
                        onClick: () {
                          if (isDelete == true) {
                            logic.postUserDeleteTrc20Address();
                          } else {
                            logic.postUserSecurityVerify();
                          }
                        },
                      )),
                ],
              ),
            ),
          );
        });
  }
}
